﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;

namespace Touchscreen
{
    public partial class Stap2 : System.Web.UI.Page
    {
        private Voorstelling v;

        protected void Page_Load(object sender, EventArgs e)
        {
            v = (Voorstelling)Session["voorstelling"];

            if (v == null)
            {
                Response.Redirect("Stap1.aspx");
            }
            else
            {              
                initComponents();
            }           
        }

        private void initComponents()
        {
            Master.labelExplain.Text = "Kies aantal kaartjes";
            Movie movie = (Movie)LoadControl("Movie.ascx");
            movie.voorstelling = v;
            Panel.Controls.Add(movie);    

            if (ViewState["adultcounter"] == null)       { ViewState["adultcounter"] = 0; }
            if (ViewState["childcounter"] == null)       { ViewState["childcounter"] = 0; }
            if (ViewState["50pluscounter"] == null)      { ViewState["50pluscounter"] = 0; }
            if (ViewState["studentcounter"] == null)     { ViewState["studentcounter"] = 0; }
            if (ViewState["3dglassescounter"] == null)   { ViewState["3dglassescounter"] = 0; }

            if (v.Film._3d == false)
            {
            Label3dCounter.Visible = false;
            Button3dPlus.Visible = false;
            Button3dMin.Visible = false;
            Label3dText.Visible = false;
            }
            else
            {
            Label3dCounter.Visible = true;
            Button3dPlus.Visible = true;
            Button3dMin.Visible = true;
            Label3dText.Visible = true;
            }     
       
            checkCount();
        }

        //Totaal aantal geselecteerde kaarten controleren.
        private void checkCount()
        {
            int count = (int)ViewState["adultcounter"] + (int)ViewState["childcounter"] + (int)ViewState["50pluscounter"] +
                        (int)ViewState["studentcounter"] + (int)ViewState["3dglassescounter"];

            if (count > 0)
            {
                ButtonNext.Enabled = true;
            }
            else
            {
                ButtonNext.Enabled = false;
            }
        }

        //De acties achter de kaartaantal knoppen.
        protected void ImageButtonAdultUp_Click(object sender, EventArgs e)
        {
            int counter = (int)ViewState["adultcounter"] + 1;
            ViewState["adultcounter"] = counter;
            LabelAdultCounter.Text = Convert.ToString(counter);
            checkCount();
            if (v.Film._3d == true)
            {
                ImageButton3dUp_Click(null, null);
            }
        }

        protected void ImageButtonAdultDown_Click(object sender, EventArgs e)
        {
            if ((int)ViewState["adultcounter"] != 0)
            {
                int counter = (int)ViewState["adultcounter"] - 1;
                ViewState["adultcounter"] = counter;
                LabelAdultCounter.Text = Convert.ToString(counter);
                checkCount();
                if (v.Film._3d == true)
                {
                    if (((int)ViewState["adultcounter"] + (int)ViewState["childcounter"] + (int)ViewState["50pluscounter"] + (int)ViewState["studentcounter"]) < (int)ViewState["3dglassescounter"])
                    {
                        ImageButton3dDown_Click(null, null);
                    }
                }
            }          
        }

        protected void ImageButtonChildUp_Click(object sender, EventArgs e)
        {
            int counter = (int)ViewState["childcounter"] + 1;
            ViewState["childcounter"] = counter;
            LabelChildCounter.Text = Convert.ToString(counter);
            checkCount();
            if (v.Film._3d == true)
            {
                ImageButton3dUp_Click(null, null);
            }
        }

        protected void ImageButtonChildDown_Click(object sender, EventArgs e)
        {
            if ((int)ViewState["childcounter"] != 0)
            {
                int counter = (int)ViewState["childcounter"] - 1;
                ViewState["childcounter"] = counter;
                LabelChildCounter.Text = Convert.ToString(counter);
                checkCount();
                if (v.Film._3d == true)
                {
                    if (((int)ViewState["adultcounter"] + (int)ViewState["childcounter"] + (int)ViewState["50pluscounter"] + (int)ViewState["studentcounter"]) < (int)ViewState["3dglassescounter"])
                    {
                        ImageButton3dDown_Click(null, null);
                    }
                }
            }
        }

        protected void ImageButtonOldPeopleUp_Click(object sender, EventArgs e)
        {
            int counter = (int)ViewState["50pluscounter"] + 1;
            ViewState["50pluscounter"] = counter;
            LabelOldPeopleCounter.Text = Convert.ToString(counter);
            checkCount();
            if (v.Film._3d == true)
            {
                ImageButton3dUp_Click(null, null);
            }
        }

        protected void ImageButtonOldPeopleDown_Click(object sender, EventArgs e)
        {
            if ((int)ViewState["50pluscounter"] != 0)
            {
                int counter = (int)ViewState["50pluscounter"] - 1;
                ViewState["50pluscounter"] = counter;
                LabelOldPeopleCounter.Text = Convert.ToString(counter);
                checkCount();
                if (v.Film._3d == true)
                {
                    if (((int)ViewState["adultcounter"] + (int)ViewState["childcounter"] + (int)ViewState["50pluscounter"] + (int)ViewState["studentcounter"]) < (int)ViewState["3dglassescounter"])
                    {
                        ImageButton3dDown_Click(null, null);
                    }
                }
            }
        }

        protected void ImageButtonStudentUp_Click(object sender, EventArgs e)
        {
            int counter = (int)ViewState["studentcounter"] + 1;
            ViewState["studentcounter"] = counter;
            LabelStudentCounter.Text = Convert.ToString(counter);
            checkCount();
            if (v.Film._3d == true)
            {
                ImageButton3dUp_Click(null, null);
            }
        }

        protected void ImageButtonStudentDown_Click(object sender, EventArgs e)
        {
            if ((int)ViewState["studentcounter"] != 0)
            {
                int counter = (int)ViewState["studentcounter"] - 1;
                ViewState["studentcounter"] = counter;
                LabelStudentCounter.Text = Convert.ToString(counter);
                checkCount();
                if (v.Film._3d == true)
                {
                    if (((int)ViewState["adultcounter"] + (int)ViewState["childcounter"] + (int)ViewState["50pluscounter"] + (int)ViewState["studentcounter"]) < (int)ViewState["3dglassescounter"])
                    {
                        ImageButton3dDown_Click(null, null);
                    }
                }
            }
        }

        protected void ImageButton3dUp_Click(object sender, EventArgs e)
        {
            if ((int)ViewState["3dglassescounter"] < ((int)ViewState["adultcounter"]+(int)ViewState["childcounter"]+(int)ViewState["50pluscounter"]+(int)ViewState["studentcounter"]))
            {
                int counter = (int)ViewState["3dglassescounter"] + 1;
                ViewState["3dglassescounter"] = counter;
                Label3dCounter.Text = Convert.ToString(counter);
                checkCount();
            }
        }

        protected void ImageButton3dDown_Click(object sender, EventArgs e)
        {
            if ((int)ViewState["3dglassescounter"] != 0)
            {
                int counter = (int)ViewState["3dglassescounter"] - 1;
                ViewState["3dglassescounter"] = counter;
                Label3dCounter.Text = Convert.ToString(counter);
                checkCount();
            }
        }

        protected void ButtonNext_Click(object sender, EventArgs e)
        {
            Session["adults"] = ViewState["adultcounter"];
            Session["childeren"] = ViewState["childcounter"];
            Session["50plus"] = ViewState["50pluscounter"];
            Session["students"] = ViewState["studentcounter"];
            Session["3dglasses"] = ViewState["3dglassescounter"];

            Response.Redirect("Stap3.aspx");
        }
    }
}